package org.jash.demo2205.entity

import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import org.jash.demo2205.BR
import org.jash.demo2205.utils.bus

data class CartItem(
    val goods_default_icon: String,
    val goods_default_price: Float,
    val goods_desc: String,
    val goods_id: Int,
    val id: Int,
    val order_id: Int,
    val user_id: Int
):BaseObservable() {
    @Bindable
    var checked = false
        set(value) {
            field = value
            bus.postValue("更新购物车" to "")
            notifyPropertyChanged(BR.checked)
        }
    @Bindable
    var count: Int = 0
        set(value) {
            if(value <= 0) {
                return
            }
            field = value
            if (checked) {
                bus.postValue("更新购物车" to "")
            }
            notifyPropertyChanged(BR.count)
        }
    fun changeCount(n:Int) {
        count += n
    }
    fun delete() {
        bus.postValue("删除购物车" to this)
    }
}